//
//  VisitorTableViewController.swift
//  Weibo8023
//
//  Created by styshy on 15/12/6.
//  Copyright © 2015年 sz. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    
    /// 用户登录标记
    private var userLogin = UserAccountViewModel.sharedUserAccount.userLogin

    // 此处不可以设置懒加载，因为登陆的时候，这个值为nil，不需要加载
    var visitorView: VisitorView?
    
    override func loadView() {
        
        // 根据用户登录情况，决定显示的根视图
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    /// 设置访客视图 - 让每一个`小`函数
    private func setupVisitorView() {
        // 替换根视图
        visitorView = VisitorView()
        view = visitorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "clickRegisterButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "clickLoginButton")
        
        visitorView?.registerButton.addTarget(self, action: "clickRegisterButton", forControlEvents: .TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "clickLoginButton", forControlEvents: .TouchUpInside)
    }
    
    @objc private func clickRegisterButton(){
        print("点击注册按钮")
    }
    
    @objc private func clickLoginButton(){
        let oVc = OAuthViewController()

        let navi = UINavigationController(rootViewController: oVc)
        
        presentViewController(navi, animated: true, completion: nil)
    }
}
